#include "config/arg_config.h"
#include "config/global_info.h"
#include "quantum.h"
#include "utils/logger.h"
#include <argparse/argparse.hpp>
#include <bg_helper/to_string.hpp>
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/spdlog.h>

int main(int argc, char **argv) {
	// init logger
	auto logger =
		spdlog::basic_logger_mt(info::LOGGER_NAME, "logs/log.txt", true);
	spdlog::set_default_logger(logger);
	spdlog::flush_on(spdlog::level::info);

	// parse args
	argparse::ArgumentParser program(info::PROGRAM_NAME);
	program.add_description(info::PROGRAM_DISCRIPTION);
	program.add_argument("f", "filename")
		.help("target file to open")
		.default_value(std::vector<std::string>({""}))
		.remaining();

	try {
		program.parse_args(argc, argv);
	} catch (const std::runtime_error &err) {
		std::cerr << err.what() << std::endl;
		std::cerr << program;
		std::exit(1);
	}

	const std::vector filenames = program.get<std::vector<std::string>>("f");

	spdlog::info("filenames: {}", bg_helper::to_string<char>(filenames));
	ArgConfig config;
	config.filenames = std::move(filenames);
	Quantum quantum(config);
	return quantum.run();
}
